package com.buer.storage.controller;


import com.buer.storage.commom.JsonResult;
import com.buer.storage.entity.Stock;
import com.buer.storage.entity.Stockdetails;
import com.buer.storage.service.StockService;
import com.buer.storage.service.StockdetailsService;
import com.buer.storage.vo.R;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/Stockdetails")
public class StockdetailsController {
    @Resource
    private StockdetailsService stockdetailsService;

    @Autowired
    private StockService stockService;

    @PostMapping("/selectStockdetailsAll")
    public JsonResult selectStockdetailsAll(@RequestBody Map<String,Object> params){
        PageInfo<Stockdetails> entityList = stockdetailsService.selectStockdetailsAll(params);
        Map result=new HashMap<>();
        result.put("total",entityList.getTotal());
        result.put("list",entityList.getList());
        return new JsonResult(1,result);
    }

    @PostMapping("/getStock")
    public JsonResult getStock(@RequestBody Map<String,Object> params) {
        PageInfo<Stockdetails> entityList = stockdetailsService.getStock(params);
        Map result=new HashMap<>();
        result.put("total",entityList.getTotal());
        result.put("list",entityList.getList());
        return new JsonResult(1,result);
    }

    @PostMapping("/searchStock")
    public JsonResult searchStock(@RequestBody Map<String,Object> params){
        PageInfo<Stockdetails> entityList = stockdetailsService.searchStock(params);
        Map result=new HashMap<>();
        result.put("total",entityList.getTotal());
        result.put("list",entityList.getList());
        return new JsonResult(1,result);
    }

    @PostMapping("/getStockDetailsByStockId")
    public R getStockDetailsByStockId(@RequestBody Map<String,Object> params){
        Stock one = stockService.getOne(params);
        Map<String,Object> ifMap=new HashMap<>();
        ifMap.put("prodCode",one.getProdCode());
        ifMap.put("prodArea",one.getProdArea());
        ifMap.put("prodDepart",one.getProdDepart());
        ifMap.put("prodStatus","0");
        List<Stockdetails> stockdetailsList = stockdetailsService.getStockdetailsList(ifMap);
        return R.ok(stockdetailsList);
    }


}
